package cms.util;

import cms.entity.Bill;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class arrToObject {

    public static Object invokeMethodBill(String[] arr) throws Exception {
        Object obj = Bill.class.newInstance();//创建对象实例
        Field[] fields = Bill.class.getDeclaredFields();//返回Bill类中的所有字段
        for (int i = 0; i < fields.length-2; i++) {
            Field f = fields[i];
            //使用java.beans.PropertyDescriptor获取Method
            PropertyDescriptor pd = new PropertyDescriptor(f.getName(), Bill.class);
            Method m = pd.getWriteMethod();//获取对象的写入方法
            m.invoke(obj, arr[i]);
        }
        return obj;
    }

    public static String[] fillZero(String[] arr){

        if(arr.length<77){
            String[] newArr=new String[77];
            for(int i=0;i<77;i++){
                newArr[i]=" ";
            }
            System.arraycopy(arr, 0, newArr, 0, arr.length);
            arr=newArr;
        }
        return arr;
    }

/*    public static void main(String[] args) {
        Vo v = new Vo();
        String[] arr = {  "张三","1", "北京市" };
        try {
            v = (Vo) invokeMethod(arr);
            System.out.println(v);
            System.out.println("id"+v.getId());
            System.out.println("name"+v.getName());
            System.out.println("address"+v.getAddress());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    */

}
